/*   1:    */ package org.intellij.plugins.relaxNG.validation;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.XmlElementVisitor;
import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.psi.xml.*;
import com.intellij.xml.util.XmlUtil;
import org.jetbrains.annotations.NotNull;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.ext.Attributes2Impl;
import org.xml.sax.ext.Locator2Impl;

import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */ 
/*  29:    */ class Psi2SaxAdapter
/*  30:    */   extends XmlElementVisitor
/*  31:    */   implements PsiElementProcessor<PsiElement>
/*  32:    */ {
/*  33:    */   private final ContentHandler a;
/*  34:    */   
/*  35:    */   public Psi2SaxAdapter(ContentHandler paramContentHandler)
/*  36:    */   {
/*  37: 45 */     this.a = paramContentHandler;
/*  38:    */   }
/*  39:    */   
/*  40:    */   public void visitXmlElement(XmlElement paramXmlElement)
/*  41:    */   {
/*  42: 49 */     if ((paramXmlElement instanceof XmlEntityRef)) {
/*  43: 50 */       XmlUtil.processXmlElements(paramXmlElement, this, false, true);
/*  44:    */     }
/*  45: 52 */     super.visitXmlElement(paramXmlElement);
/*  46:    */   }
/*  47:    */   
/*  48:    */   public void visitXmlToken(XmlToken paramXmlToken)
/*  49:    */   {
/*  50: 56 */     if (paramXmlToken.getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
/*  51: 57 */       a(paramXmlToken, paramXmlToken.getText());
/*  52:    */     }
/*  53:    */   }
/*  54:    */   
/*  55:    */   private void a(XmlElement paramXmlElement, String paramString)
/*  56:    */   {
/*  57:    */     try
/*  58:    */     {
/*  59: 63 */       a(paramXmlElement);
/*  60: 64 */       this.a.characters(paramString.toCharArray(), 0, paramString.length());
/*  61:    */     }
/*  62:    */     catch (SAXException localSAXException)
/*  63:    */     {
/*  64: 66 */       throw new ParseError(localSAXException);
/*  65:    */     }
/*  66:    */   }
/*  67:    */   
/*  68:    */   public boolean execute(@NotNull PsiElement paramPsiElement)
/*  69:    */   {
/*  70: 71 */     if (paramPsiElement == null) {
/*  71: 71 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/validation/Psi2SaxAdapter", "execute" }));
/*  72:    */     }
/*  73: 71 */     paramPsiElement.accept(this);
/*  74: 72 */     return true;
/*  75:    */   }
/*  76:    */   
/*  77:    */   public void visitXmlDocument(XmlDocument paramXmlDocument)
/*  78:    */   {
/*  79:    */     try
/*  80:    */     {
/*  81: 77 */       this.a.startDocument();
/*  82: 78 */       XmlTag localXmlTag = paramXmlDocument.getRootTag();
/*  83: 79 */       if (localXmlTag != null) {
/*  84: 80 */         localXmlTag.accept(this);
/*  85:    */       }
/*  86: 82 */       this.a.endDocument();
/*  87:    */     }
/*  88:    */     catch (SAXException localSAXException)
/*  89:    */     {
/*  90: 84 */       throw new ParseError(localSAXException);
/*  91:    */     }
/*  92:    */   }
/*  93:    */   
/*  94:    */   public void visitXmlTag(XmlTag paramXmlTag)
/*  95:    */   {
/*  96:    */     try
/*  97:    */     {
/*  98: 90 */       a(paramXmlTag);
/*  99:    */       
/* 100: 92 */       Map localMap = paramXmlTag.getLocalNamespaceDeclarations();
/* 101: 93 */       String[] arrayOfString = (String[])localMap.keySet().toArray(new String[localMap.size()]);
/* 102: 94 */       for (Object localObject3 : arrayOfString) {
/* 103: 95 */         this.a.startPrefixMapping(localObject3, (String)localMap.get(localObject3));
/* 104:    */       }
/* 105: 98 */       ??? = new Attributes2Impl();
/* 106: 99 */       XmlAttribute[] arrayOfXmlAttribute = paramXmlTag.getAttributes();
/* 107:    */       String str4;
/* 108:100 */       for (localPsiElement : arrayOfXmlAttribute)
/* 109:    */       {
/* 110:101 */         String str3 = localPsiElement.getName();
/* 111:102 */         if ((!"xmlns".equals(str3)) && (!str3.startsWith("xmlns:")))
/* 112:    */         {
/* 113:103 */           str4 = localPsiElement.getNamespace();
/* 114:104 */           ((Attributes2Impl)???).addAttribute(str3.contains(":") ? str4 : "", localPsiElement.getLocalName(), str3, "PCDATA", localPsiElement.getValue());
/* 115:    */         }
/* 116:    */       }
/* 117:108 */       ??? = paramXmlTag.getNamespace();
/* 118:109 */       String str1 = paramXmlTag.getLocalName();
/* 119:110 */       String str2 = paramXmlTag.getName();
/* 120:111 */       this.a.startElement((String)???, str1, str2, (Attributes)???);
/* 121:    */       
/* 122:113 */       PsiElement localPsiElement = paramXmlTag.getFirstChild();
/* 123:114 */       while (localPsiElement != null)
/* 124:    */       {
/* 125:115 */         localPsiElement.accept(this);
/* 126:116 */         localPsiElement = localPsiElement.getNextSibling();
/* 127:    */       }
/* 128:119 */       this.a.endElement((String)???, str1, str2);
/* 129:121 */       for (int n = arrayOfString.length - 1; n >= 0; n--)
/* 130:    */       {
/* 131:122 */         str4 = arrayOfString[n];
/* 132:123 */         this.a.endPrefixMapping(str4);
/* 133:    */       }
/* 134:    */     }
/* 135:    */     catch (SAXException localSAXException)
/* 136:    */     {
/* 137:126 */       throw new ParseError(localSAXException);
/* 138:    */     }
/* 139:    */   }
/* 140:    */   
/* 141:    */   public void visitXmlText(XmlText paramXmlText)
/* 142:    */   {
/* 143:131 */     a(paramXmlText, paramXmlText.getValue());
/* 144:    */   }
/* 145:    */   
/* 146:    */   private void a(PsiElement paramPsiElement)
/* 147:    */   {
/* 148:135 */     PsiFile localPsiFile = paramPsiElement.getContainingFile();
/* 149:136 */     Document localDocument = PsiDocumentManager.getInstance(paramPsiElement.getProject()).getDocument(localPsiFile);
/* 150:137 */     if (localDocument == null) {
/* 151:138 */       return;
/* 152:    */     }
/* 153:140 */     VirtualFile localVirtualFile = localPsiFile.getVirtualFile();
/* 154:141 */     if (localVirtualFile == null) {
/* 155:142 */       return;
/* 156:    */     }
/* 157:145 */     Locator2Impl localLocator2Impl = new Locator2Impl();
/* 158:146 */     localLocator2Impl.setSystemId(RngParser.reallyFixIDEAUrl(localVirtualFile.getUrl()));
/* 159:    */     
/* 160:148 */     int i = paramPsiElement.getTextRange().getEndOffset();
/* 161:149 */     int j = localDocument.getLineNumber(i);
/* 162:    */     
/* 163:151 */     localLocator2Impl.setLineNumber(j + 1);
/* 164:152 */     localLocator2Impl.setColumnNumber(1 + i - localDocument.getLineStartOffset(j));
/* 165:    */     
/* 166:154 */     this.a.setDocumentLocator(localLocator2Impl);
/* 167:    */   }
/* 168:    */   
/* 169:    */   public static class ParseError
/* 170:    */     extends RuntimeException
/* 171:    */   {
/* 172:    */     public ParseError(SAXException paramSAXException)
/* 173:    */     {
/* 174:159 */       super();
/* 175:    */     }
/* 176:    */   }
/* 177:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.validation.Psi2SaxAdapter

 * JD-Core Version:    0.7.0.1

 */